#!/usr/bin/perl
#config_log.cgi

require './mdmhistory-lib.pl';

&ReadParse();

&header($text{'log_properties'},undef,"config",undef,0);

my $filename=$config{'mdmlogfile'};
my $file_conf = $config{'file_conf'};

if( ! -s $file_conf ) { 
	&error($text{'log_cannotfind'});
}

print "<form action=save_conf.cgi method=post onsubmit='return onsubmit_form();'>\n";
&foreign_require("naslog","naslog-lib.pl");
my ($name,$size,$opt,$max)=&foreign_call("naslog","get_conf_data",$filename);
print "<input type=hidden name=name value=$name>\n";

my @fs=stat($filename);

my $atime=localtime($fs[8]);
my $mtime=localtime($fs[9]);
my $ctime=localtime($fs[10]);

if ( $name ne $filename )  {
	&error($text{'log_cannotstat'});
}

$size=floor($size/1024);
print <<EOF;
<table class=mode1 border=0 width=100% align=center cellspacing=0 cellpadding=0>
    <tr class=mode1>
        <td><b>$text{'log_size'}:<b></td>
        <td> $fs[7] </td>
    </tr>
    <tr class=mode2>
        <td><b>$text{'log_atime'}:<b></td>
        <td> $atime </td>
    </tr>
    <tr class=mode1>
        <td><b>$text{'log_mtime'}:<b></td>
        <td> $mtime </td>
    </tr>
    <tr class=mode2>
        <td><b>$text{'log_ctime'}:<b></td>
        <td> $ctime  </td>
    </tr>

<tr><td>&nbsp;</td></tr>
<tr>
<td><b>$text{'log_maxsize'}:</b></td>
<td>
<input class=text type=text size=18 name=size value=$size >
&nbsp;<b>K $text{'bytes'}</b>
</td>
</tr>
EOF

print "<tr>\n";
print "<td><b>$text{'log_option'}:</b></td>\n";
print "<td><select name=opt size=1 >\n";

my @olist=split(";",$text{'select'});

for ($i=0;$i<@olist;$i++){
	if($max == $i ) {
		print "<option value=$i name=num selected>";
	} else {
		print "<option value=$i name=num>";
	}
	print "$olist[$i]</option>\n";
}

print "</select></td>\n";
print "</tr>\n";

print <<EOF;
<tr><td>&nbsp;<td></tr>
<tr><td><input class=button1 name=setup type=submit value=$text{'submit'} ><td></tr>
</table>
<script>
function onsubmit_form()
{
	if( isNaN(document.forms[0].size.value) ) {
		alert("$text{'errorinput'}");
		return false;
	}
	if(document.forms[0].size.value <1 ) {
		alert("$text{'smallinput'}");
		return false;
	}
	if(document.forms[0].size.value>10000) {
		alert("$text{'biginput'}");
		return false;
	}
        document.forms[0].setup.disabled = true;
}
</script>
EOF


print "</form>\n";
&footer("index.cgi", $text{'index_title'});

